package com.norns.torque.dialog

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hi.dhl.binding.viewbind
import com.norns.torque.databinding.DialogSingleButtonBinding

class SingleButtonDialog:CommonDialog() {

    private val binding by viewbind<DialogSingleButtonBinding>()
    companion object{
        fun newInstance(title:String,content:String): SingleButtonDialog{
            val args = Bundle()
            val fragment = SingleButtonDialog()
            args.putString("content",content)
            args.putString("title",title)
            fragment.arguments = args
            return fragment
        }
        fun newInstance(title:String,content:String,backgroundRes:Int):SingleButtonDialog {
            val args = Bundle()
            args.putString("content",content)
            args.putString("title",title)
            args.putInt("background",backgroundRes)
            val fragment = SingleButtonDialog()
            fragment.arguments = args
            return fragment
        }
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        screenWidthAspect=0.9f
        isCancelableOutside=false
        return binding.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val content=arguments?.getString("content")?:""
        val title=arguments?.getString("title")?:""
        val backgroundRes=arguments?.getInt("background")?:0
        if (backgroundRes!=0){
            binding.root.setBackgroundResource(backgroundRes)
            binding.tvMsg.setTextColor(Color.WHITE)
            binding.tvTitle.setTextColor(Color.WHITE)
        }
        binding.tvMsg.text=content
        binding.tvTitle.text=title
        binding.btnConfirm.setOnClickListener {
            dismiss()
        }
    }
}